/*************************************************************************i
    > File Name: nfa.cpp
    > Author: liujing
    > Mail: jingliu.cs@gmail.com 
    > Created Time: 2014年10月20日 星期一 21时36分45秒
 ************************************************************************/

#include "nfa.h"
#include <math.h>

GraphNode::GraphNode(void){
	this->ID=id++;
}

GraphNode::~GraphNode(void){
}

int GraphNode::id=0;

void GraphNode::resetID(){
	id=0;
}

int GraphNode::getID(){
	return ID;
}

EdgeLink::EdgeLink(void):backEdge(false){
}

EdgeLink::~EdgeLink(void){
}
EdgeLink::EdgeLink(GraphNode * graphNode,wchar_t str){
	this->graphNode=graphNode;
	this->str=str;
	this->backEdge=false;
}

EdgeLink::EdgeLink(GraphNode* graphNode,wchar_t str,bool backEdge){
	this->graphNode=graphNode;
	this->str=str;
	this->backEdge=backEdge;
}

GraphLine::GraphLine(void){
}

GraphLine::~GraphLine(void){
}

GraphLine::GraphLine(GraphNode* graphNode){
	this->graphNode=graphNode;
}

Graph::Graph(void){
}

Graph::~Graph(void){
}

Graph::Graph(int n){
	int i;
	// reset, increase from 0
	GraphNode::resetID();
	for(i=0;i<n;i++){
		//
		GraphLine* graphLineGen=new GraphLine(new GraphNode());
		this->graphLines.push_back(graphLineGen);

	}
	this->start=0;
	this->end=0;
}
//add edge from n1 to n2
void Graph::addEdge(GraphNode n1,GraphNode n2,wchar_t str){
	int i=0;
	for(;i<graphLines.size();i++){
		if(graphLines[i]->graphNode->ID==n1.ID){
			graphLines[i]->graphNodes.push_back(new EdgeLink(new GraphNode(n2),str));
			break;
		}
	}
}

void Graph::addBackEdge(GraphNode n1, GraphNode n2,wchar_t str){
	int i=0;
	for(;i<graphLines.size();i++){
		if(graphLines[i]->graphNode->ID==n1.ID){
			graphLines[i]->graphNodes.push_back(new EdgeLink(new GraphNode(n2),str,true));
		break;
		}
	}
}
